<?php $myLib = new myLib(); ?>
<?php $suattr = $sf_user->getAttribute('suattr') ?>
<?php include_component('includes','submenu') ?>
<fieldset style="background-color: white;">
<div style="float: left;width: 670px;min-height: 200px;">
  <div style="padding: 10px 10px 0 10px;float: left;width: 650px;">
    <?php include_component('includes','miniSearch') ?>
  </div>
<form id="frmArticleShow" action="" method="post">
    <input type="hidden" id="hdId" value="<?php echo $article->getId() ?>" />
  <div style="padding: 0 10px 10px 10px;float: left;">
    <div class="articulo background_body">
        <div style="width: 100%;height: 40px;float: left;">
            <div class="abbr_date">
              <div style="padding: 9px;">
                <?php echo $myLib->formattedDateAbbr($article->getCreatedAt(),$sf_user->getCulture()); ?></div>
            </div>
            <div style="width: 380px;float: left;">
              <div style="padding: 13px;">
                <?php echo $article->getCategory()->getDescription().' / '.$article->getSubcategory()->getDescription() ?>
              </div>
            </div>
            <div style="width: 170px;float: left;">
              <div style="padding: 11px;">
                Rating:
                <?php for($j=1;$j<=5;$j++){ ?>
                  <?php if($j<=round($article->getScore())){ ?>
                    <?php echo image_tag('estrella_on.png') ?>
                  <?php }else{ ?>
                    <?php echo image_tag('estrella.png') ?>
                  <?php } ?>
                <?php } ?>
              </div>
            </div>
        </div>
        <div style="width: 100%;float: left;">
            <div style="margin: 0 20px;float: left;">
                <table width="100%">
                    <tr>
                        <td>
                            <div style="border: 7px solid white;">
                                <?php echo image_tag('/uploads/author/'.$article->getOwnerId().'.jpg','size=100x100') ?>
                            </div>
                        </td>
                        <td style="text-align: justify;">
                          <div style="padding: 15px;">
                            <?php echo $article->getLanguage()->getDescription() ?>, <?php echo $article->getCountry()->getName() ?>
                            <br />
                            Tipo de articulo: <?php echo $article->getArticleType()->getDescription() ?>
                          </div>
                            <h1 style="padding: 15px;"><?php echo $article->getTitle() ?></h1>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div style="width: 100%;float: left;margin-top: 20px;">
            <div style="margin: 0 20px 20px 20px;float: left;text-align: justify;">
              <?php echo $sf_data->getRaw('article')->getSummary() ?>
                <br /><br />
              <?php echo $sf_data->getRaw('article')->getContentFree() ?>
            </div>
        </div>
        <div style="width: 100%;float: left;" class="borde_redondeado">
            <div style="margin: 10px 20px;float: left;text-align: justify;">
                <div id="contenidoExclusivo">
                  <?php if($sf_user->isAuthenticated()){ ?>
                      <?php if(is_object($article_payment) || $sf_user->getAttribute('suid')==$article->getOwnerId()){/* si el costo NO es objeto, es porque ha pagado anteriormente */ ?>
                        <table width="100%">
                            <tr>
                                <td><b>Contenido Exclusivo</b></td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td><?php echo $sf_data->getRaw('article')->getContentPremium() ?></td>
                            </tr>
                        </table>
                    <br /><br />
                        <?php if($can_score=='1'){/* si permite puntuar */ ?>
                            Puntuar artículo:
                            <?php
                                for($i=1;$i<=5;$i++){
                                    echo image_tag('estrella_on.png','id="star_'.$i.'" class="star" onclick="star_save('.$i.');ajaxSaveScore('.$article->getId().','.$i.');" onmouseover="star_on('.$i.')" onmouseout="star_clear()" style="cursor: pointer;"');
                                }
                            ?>
                            <input type="hidden" id="estrellas" name="estrellas" />
                        <?php } ?>
                      <?php } ?>
                  <?php } ?>
                <!------------------------------------------------------------------------------>
                    <?php if($sf_user->isAuthenticated()){/* si esta logueado le sale la opcion para pagar */ ?>
                      <?php if($sf_user->getAttribute('suid')!=$article->getOwnerId()){/* si yo no soy el dueño */ ?>
                        <?php if(!is_object($article_payment)){/* si el pago es objeto, es porque ya PAGO anteriormente */ ?>
                          <a href="<?php echo url_for('@articleReadFull?id='.$article->getId()) ?>" onclick="return confirm_readFull('<?php echo $article_cost->getCost()->getCost() ?>')">
                              <b>Leer completo [<?php echo $article_cost->getCost()->getCost() ?> $USD]</b></a>
                        <?php } ?>
                      <?php } ?>
                    <?php }else{/* si no esta logueado lo invita a crearse una cuenta */ ?>
                        <b><a href="<?php echo url_for('@register_form') ?>">Leer todo el art&iacute;culo [<?php echo $article_cost->getCost()->getCost() ?> $USD]</a></b>
                    <?php } ?>
                </div>
            </div>
        </div>
        <div style="width: 100%;float: left;margin-top: 5px;" class="borde_redondeado barra_articulo">
            <div style="float: left;">
                <ul>
                    <?php if($sf_user->isAuthenticated()){ ?>
                    <li class="options">
                        <div style="display: block;">
                            <a class="fancyBox" href="#fancyReportar">
                                <div style="display: inline-block;vertical-align: middle;">
                                    Reportar
                                </div>
                                <div style="display: inline-block;vertical-align: middle;">
                                    <?php echo image_tag('warning.png','size=16x16') ?>
                                </div>
                            </a>
                        </div>
                    </li>
                    <li class="options">
                        <div id="divAddRemoveFavorites" style="display: block;">
                          <?php if(!$already_favorite){/* si NO pertenece a mis favoritos */ ?>
                            <a href="javascript:void(0)" onclick="ajaxAddFavorites('<?php echo $article->getId() ?>')">
                                <div style="display: inline-block;vertical-align: middle;width: 126px;">
                                    Agregar a mis favoritos
                                </div>
                                <div style="display: inline-block;vertical-align: middle;">
                                    <?php echo image_tag('heart.png','size=16x16') ?>
                                </div>
                            </a>
                          <?php }else{/* si ya es favorito */ ?>
                            <a href="javascript:void(0)" onclick="ajaxRemoveFavorites('<?php echo $article->getId() ?>')">
                                <div style="display: inline-block;vertical-align: middle;width: 126px;">
                                    Remover de mis favoritos
                                </div>
                                <div style="display: inline-block;vertical-align: middle;">
                                    <?php echo image_tag('heart2.png','size=19x16') ?>
                                </div>
                            </a>
                          <?php } ?>
                        </div>
                    </li>
                    <?php } ?>
                    <li style="float: right;">
                      <div style="float: left;padding: 10px;">
                        <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
                      </div>
                      <div style="float: left;padding: 10px;">
                        <a name="fb_share" type="button" share_url="<?php echo $sf_request->getUri() ?>">Compartir en Facebook</a><?php slot('meta_url',$sf_request->getUri()) ?>
                      </div>
                    </li>
                </ul>
            </div>
        </div>
        <?php if(count($related_articles)>0){ ?>
        <div style="width: 100%;float: left;">
            <div style="margin: 10px 20px;float: left;text-align: justify;">
              <div class="section">
                <div class="title2">
                    <div>Los que han le&iacute;do este art&iacute;culo, también han visto</div>
                </div>
                <div style="width: 590px;height: 1px;background-color: #cdd2d6;margin-left: 10px;"></div>
                <div class="body related_list">
                  <ul>
                      <?php foreach($related_articles as $ra){ ?>
                        <li>
                            <a href="<?php echo url_for('@article?id='.$ra->getId().'&slug='.$ra->getSlug()) ?>">
                                <?php echo $ra->getTitle() ?></a>
                        </li>
                      <?php } ?>
                  </ul>
                </div>
              </div>
            </div>
        </div>
        <?php } ?>
        <?php if(count($same_owner_arts)>0){ ?>
        <div style="width: 100%;float: left;">
            <div style="margin: 10px 20px;float: left;text-align: justify;">
              <div class="section">
                <div class="title2">
                    <div>Otros art&iacute;culos del autor</div>
                </div>
                <div style="width: 590px;height: 1px;background-color: #cdd2d6;margin-left: 10px;"></div>
                <div class="body related_list">
                    <ul>
                      <?php foreach($same_owner_arts as $soart){ ?>
                        <li>
                            <a href="<?php echo url_for('@article?id='.$soart->getId().'&slug='.$soart->getSlug()) ?>">
                                <?php echo $soart->getTitle() ?></a>
                        </li>
                      <?php } ?>
                    </ul>
                </div>
              </div>
            </div>
        </div>
        <?php } ?>
        <div style="width: 100%;float: left;">
            <div style="margin: 10px 20px;float: left;text-align: justify;">
              <div class="section">
                <div class="title2">
                    <div>Respuestas a este art&iacute;culo</div>
                </div>
                <div style="width: 590px;height: 1px;background-color: #cdd2d6;margin-left: 10px;"></div>
                <div class="body related_list">
                  <?php if(count($responses)>0){ ?>
                      <?php foreach($responses as $response){ ?>
                      <ul>
                        <li>
                            <a href="<?php echo url_for('@article?id='.$response->getId().'&slug='.$response->getSlug()) ?>">
                                <?php echo $response->getTitle() ?></a>
                        </li>
                      <?php } ?>
                      </ul>
                  <?php }else{ ?>
                      <div style="padding: 10px;margin-left: 25px;">Este art&iacute;culo no tiene respuestas</div>
                  <?php } ?>
                  <?php if($sf_user->isAuthenticated()){ ?>
                    <?php if(is_object($article_payment) || $sf_user->getAttribute('suid')==$article->getOwnerId()){/* si el costo NO es objeto, es porque ha pagado anteriormente */ ?>
                    <div style="margin-left: 35px;">
                        <a href="<?php echo url_for('@articles_new?response_of='.$article->getId()) ?>">
                            <b>Responder a este art&iacute;culo</b></a>
                    </div>
                    <?php } ?>
                  <?php } ?>
                </div>
              </div>
            </div>
        </div>
      </div>
  </div>
  <div style="padding: 0 10px;float: left;">
    <div style="width: 650px;" class="background_gray">
        <div style="padding: 9px;margin-left: 20px;color: white;font-weight: bold;">
            <label style="font-size: 13px;">Comentarios</label>
            <div style="float: right;margin-right: 20px;">
                <?php echo image_tag('comentario-blanco.png') ?>
            </div>
            <div style="float: right;margin-right: 20px;">
                <?php echo count($comments) ?>
            </div>
        </div>
    </div>
  </div>
  <div style="padding: 0 10px;float: left;">
    <div style="width: 650px;float: left;">
      <?php foreach($comments as $comment){ ?>
        <div id="comment_<?php echo $comment->getId() ?>" class="comment background_body" style="margin-bottom: 2px;">
          <div class="photo">
              <?php echo image_tag('/uploads/author/'.$comment->getOwnerId().'.jpg','size=40x40') ?>
          </div>
          <div class="text">
              <div style="padding: 10px;padding-right: 0;display: block;">
                  <div style="width: 500px;display: inline-block;vertical-align: middle;">
                      <div style="float: right;">
                          <?php echo $myLib->formattedDate($comment->getCreatedAt()) ?>
                      </div>
                      <b>Pedro Bazán Lévano</b>
                      <br /><br />
                      <p align="justify">
                          <?php echo $comment->getComment() ?>
                      </p>
                  </div>
                  <div style="width: 30px;display: inline-block;vertical-align: top;text-align: center;">
                      <?php if($comment->getOwnerId()==$sf_user->getAttribute('suid')){ ?>
                      <a href="javascript:void(0)" title="Delete this comment"
                         onclick="return deleteComentario('<?php echo $comment->getId() ?>');" class="hidden btn_delete">
                          <?php echo image_tag('eliminar.png','size=16x16') ?></a>
                      <?php } ?>
                  </div>
              </div>
          </div>
        </div>
      <?php } ?>
    <div id="newComment" style="display: none;"></div>
      <?php if($sf_user->isAuthenticated()){ ?>
        <?php if(is_object($article_payment) || $sf_user->getAttribute('suid')==$article->getOwnerId()){/* si el costo NO es objeto, es porque ha pagado anteriormente */ ?>
          <div class="comment background_body">
            <div class="photo">
                <a href="javascript:void(0)" onclick="ajaxComentar()">
                    <?php echo image_tag('bt_enviar-comentario.gif','size=45x45') ?></a>
            </div>
            <div class="text">
                <div style="padding: 10px;">
                    <textarea id="comment" rows="3" cols="95" oncontextmenu="return false" placeholder="Escribe tu comentario"></textarea>
                </div>
            </div>
          </div>
        <?php }else{ ?>
          <div style="padding: 10px;">Para realizar comentarios en este art&iacute;culo es necesario leerlo completo.</div>
        <?php } ?>
      <?php }else{ ?>
        <div style="padding: 10px;">Para realizar comentarios en este art&iacute;culo es necesario leerlo completo.</div>
      <?php } ?>
    </div>
  </div>
</form>
</div>
<div style="float: left;width: 320px;">
  <?php include_component('includes','autor', array('id' => $article->getOwnerId())) ?>
  <?php include_component('includes','destacados') ?>
</div>
</fieldset>

<?php include_component('includes','fixed', array('id' => $article->getId())) ?>

<script type="text/javascript">
$(document).ready(function(){
    $('body').attr('onscroll','onScroll();');
    $(".comment").hover(function(){
        var id = $(this).attr("id");
        $(".btn_delete").addClass("hidden");
        $("#"+id+" .btn_delete").removeClass("hidden");
    }, function(){
        $(".btn_delete").addClass("hidden");
    });
});
function ajaxComentar(){
    var comment = $("#frmArticleShow #comment").val();
    var article_id = $("#frmArticleShow #hdId").val();
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxComment') ?>",
        data: "id="+article_id+"&comment="+comment,
        success: function(html){
            $("#frmArticleShow #comment").val('');
            $("#frmArticleShow #comment").focus();
            $(html).insertBefore("#newComment").hide().fadeIn();
        }
    });
}
function deleteComentario(id){
    if(!confirm("Seguro que desea eliminar comentario?")){
        return false;
    }else{
        ajaxDeleteComentario(id);
    }
}
function ajaxDeleteComentario(comment_id){
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxDeleteComment') ?>",
        data: "id="+comment_id,
        success: function(html){
            $("#frmArticleShow #comment_"+comment_id).remove();
        }
    });
}
function confirm_readFull(cost){
    if(!confirm("Se descontarán "+cost+" $USD de su saldo. Continuar de todas formas?")){
        return false;
    }else{
        return true;
    }
}
function ajaxSaveScore(article_id, score){
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxSaveScore') ?>",
        data: "id="+article_id+"&score="+score,
        success: function(html){
            /* */
        }
    });
}
function ajaxAddFavorites(article_id){
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxAddFavorites') ?>",
        data: "id="+article_id,
        success: function(html){
            $("#divAddRemoveFavorites").html(html);
        }
    });
}
function ajaxRemoveFavorites(article_id){
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajaxRemoveFavorites') ?>",
        data: "id="+article_id,
        success: function(html){
            $("#divAddRemoveFavorites").html(html);
        }
    });
}
</script>